<template>
	<view>
		<!-- <view style="height: 20upx;"></view> -->
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30" style="padding-top: 20upx;">
			<view class="u-m-r-10">
				<u-avatar v-if="userInfo.headimgurl" :src="userInfo.headimgurl" size="140"></u-avatar>
				<u-avatar v-else src="/static/zsoa/user.png" size="140"></u-avatar>
			</view>
			<view class="u-flex-1" >
				<view class="u-font-18 u-p-b-20">
					<text style="margin-right: 20upx;">{{ userInfo.nickname || '未登录' }}</text>
				<text v-if="userInfo.AccountInfo">
					<u-tag text="供应商" :size="'mini'" type="success" v-if="userInfo.AccountInfo.type == '1'"/>
					<u-tag text="销售客户" :size="'mini'" v-else-if="userInfo.AccountInfo.type == '0'"/>
				</text>
				<text v-else-if="userInfo.typecode === '0'">
					<u-tag text="内部用户" :size="'mini'" type="warning"/>
				</text>
				</view>
				<view class="u-font-14 u-tips-color">{{ userInfo.Account || '未绑定账号' }}</view>
			</view>
			<view class="u-m-l-10 u-p-10"><u-icon name="bell" color="#0074E0" size="40"></u-icon></view>
			<view class="u-m-l-10 u-p-10"><u-icon name="arrow-right" color="#969799" size="28"></u-icon></view>
		</view>
		
		<view class="u-m-t-20" v-if="userInfo.AccountInfo && userInfo.AccountInfo.type == '0'">
			<u-cell-group>

				<u-cell-item @click="toGoodsRemainder" icon="bookmark" color="#0074E0" title="客户信息"></u-cell-item>
 
			</u-cell-group>
		</view>
		<view class="u-m-t-20">
			<u-cell-group>
				<!-- <u-cell-item icon="home" @click="toHome" color="#0074E0" title="回到首页"></u-cell-item> -->
				<!-- <u-cell-item @click="sign" icon="edit-pen" color="#0074E0" title="签到"></u-cell-item> -->
				<u-cell-item @click="toCarList" icon="car" color="#0074E0" title="车辆管理"></u-cell-item>
				<u-cell-item @click="toMyQrcode" icon="scan" color="#0074E0" title="我的二维码"></u-cell-item>
			</u-cell-group>
		</view>

		<!-- <view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="star" title="收藏"></u-cell-item>
				<u-cell-item icon="photo" title="相册"></u-cell-item>
				<u-cell-item icon="coupon" title="卡券"></u-cell-item>
				<u-cell-item icon="heart" title="关注"></u-cell-item>
			</u-cell-group>
		</view>
		 -->
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item @click="toPage('/pages/oa/setting/setting')" icon="setting" title="设置"></u-cell-item>
			</u-cell-group>
		</view>
		
		
		<view style="margin-top: 100upx;display: flex;justify-content: center;" v-if="!userInfo.Account">
			<view style="text-decoration: underline;" class="bind-text-btn" @click="toLogin()">绑定工作人员账号</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			pic: '',
			show: true,
			nickName: '',
			account: ''
		};
	},
 
	computed: {
		...mapState('account', ['token', 'userInfo'])
	},
	methods: {
		toGoodsRemainder(){
			uni.navigateTo({
				url:"/pages/oa/goods-remainder/goods-remainder"
			})
		},
		toMyQrcode(){
			uni.navigateTo({
				url:"/pages/oa/my-qrcode/my-qrcode"
			})
		},
		async payTest() {
			uni.showLoading({
				title:"创建支付订单"
			})
			let res = await this.$ajax.post({
				url: '/WxPay/createWeightPassOrder',
				data: {
					car_id: '123'
				}
			});
			uni.hideLoading()
			
			uni.showLoading({
				title:"支付等待"
			})
			let signRes = await this.$ajax.post({
				url: '/WxPay/payWeightPassOrder',
				data: {
					order_num: res.data.order_num
				}
			});
			uni.hideLoading()
			let paySign = signRes.data
			console.log(paySign)
			let payParams = {
				appId:paySign.appId,
				timestamp: paySign.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
				nonceStr: paySign.nonceStr, // 支付签名随机串，不长于 32 位
				package: paySign.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
				signType: paySign.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
				paySign: paySign.paySign, // 支付签名
			}
			console.log(payParams)
			wxjs.chooseWXPay({
				...payParams,
			  success: function (res) {
			    // 支付成功后的回调函数
					console.log(res)
			  }
			});
		},
		toCarList() {
			if (this.token) {
				
				
				if(this.userInfo.Account){
					uni.navigateTo({
						url: '/pages/oa/car-list/car-list'
					});
				}else{
					uni.showModal({
						title: '系统提示',
						content: '请先绑定账号',
						success() {},
						showCancel: false
					});
				}
				
				// uni.navigateTo({
				// 	url: "/pages/oa/car-list/add"
				// });
			} else {
				uni.showModal({
					title: '系统提示',
					content: '请重新进入，并授权',
					success() {},
					showCancel: false
				});
			}
			
		},
		sign() {
			if (!this.userInfo.Account) {
				uni.showToast({
					title: '请先登录',
					icon: 'none'
				});
				return;
			}
			// this.$store.dispatch("account/wxLoginByCode","12312313")
			uni.navigateTo({
				url: '/pages/oa/sign/sign'
			});
			this.$store.dispatch('account/initJSsdk');
		},
		toHome() {
			window.location.href = 'http://www.fengyueweigh.com:8070/m';
		},
		toLogin() {
			// if (!this.token) {
			// 	uni.showModal({
			// 		title: '提示',
			// 		content: '请尝试重新打开页面',
			// 		confirmText: '知道了',
			// 		showCancel: false
			// 	});
			// }
			// if (this.userInfo.Account) {
			// 	return;
			// }
			uni.navigateTo({
				url: '/pages/oa/login-oa/login-oa'
			});
		},
		toPage(path) {
			uni.navigateTo({
				url: path
			});
		}
	},
	onShow() {
		console.log('person onshow');
		if (this.userInfo.Account) {
			this.pic = this.userInfo.headimgurl;
			this.nickName = this.userInfo.nickname;
			this.account = this.userInfo.Account;
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #ededed;
}

.camera {
	width: 54px;
	height: 44px;

	&:active {
		background-color: #ededed;
	}
}
.user-box {
	background-color: #fff;
}

.bind-text-btn{
	color: $u-type-primary;
}
</style>
